<?php
/*
 * JSONT-PHP
 * From legocode <http://code.google.com/p/legocode/>
 * By MindstormsKid <minstormskd@gmail.com>
 * This code is licensed under the MIT license <http://www.opensource.org/licenses/mit-license.php>
 * Documentation <http://code.google.com/p/legocode/wiki/Snippets#JSONT>
 *
 * JSONT-PHP <http://code.google.com/p/legocode/source/browse/trunk/snippets/jsont.php>
 * JSONT (JSON Tables) can create and decode tabular JSON data. This is the PHP version.
*/
function jsont_encode($keys, $d) {
	if (!is_array($keys) || !is_array($d)) { return false; }
	$arr = array();
	foreach ($d as $o) {
		foreach ($keys as $k) {
			$arr[] = $o[$k];
		}
	}
	return $arr;
}
function jsont_decode($k, $v) {
	if (!is_array($k) || !is_array($v)) { return false; }
	$arr = array(); $vlen = count($v); $klen = count($k); $start = 0; $stop = $klen;
	while ($stop <= $vlen) {
		$a = array_slice($v, $start, $stop);
		$o = array();
		for ($i = 0; $i < $klen; $i++) { $o[$k[$i]] = $a[$i]; }
		$arr[] = $o;
		$start = $stop; $stop += $klen;
	}
	return $arr;
}
?>